--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_rumia = General:new(extension, "hy_rumia", "jin_k", 4, 4, General.Female)
    local midnight = fk.CreateSkill {
        name = "midnight",
    }
    midnight:addEffect("active", {
        anim_type = "offensive",
        target_num = 1,
        card_num = 0,
        can_use = function(self, player)
            return not player:isKongcheng() and player:usedSkillTimes(midnight.name, Player.HistoryPhase) == 0
        end,
        card_filter = Util.FalseFunc,
        target_filter = function(self, player, to_select, selected, selected_cards)
            return #selected == 0 and to_select ~= Self.id and not to_select:isKongcheng()
        end,
        prompt = function(self, selected, selected_cards)
            return "midnight_prompt"
        end,
        on_use = function(self, room, effect)
            local player = effect.from
            local target = effect.tos[1]
            player:pindian({ target }, midnight.name)
        end,
    })
    midnight:addEffect(fk.PindianResultConfirmed, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(midnight.name) and (data.from == player or data.to == player) and not player.dead and
                ((data.fromCard.color == Card.Black and data.toCard.color == Card.Black) or data.reason == "midnight")
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if data.fromCard.color == Card.Black and data.toCard.color == Card.Black then
                room:drawCards(player, 2, midnight.name)
            end
            if data.reason == "midnight" then
                if data.winner == player then
                    room:setPlayerMark(player, "midnight_win-turn", 1)
                    room:setPlayerMark(player, "@midnight_mark-turn", "midnight_win")
                else
                    room:setPlayerMark(player, "midnight_lose-turn", 1)
                    room:setPlayerMark(player, "@midnight_mark-turn", "midnight_lose")
                end
                room:setPlayerMark(data.to, "midnight_target-turn", 1)
            end
        end
    })
    midnight:addEffect(fk.PindianFinished, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(midnight.name) and target == player and data.reason == "midnight"
        end,
        on_cost = function(self, event, target, player, data)
            if player.id > 0 or player.serverplayer:getId() > 0 then
                local success, dat = player.room:askToUseActiveSkill(player, {
                    skill_name = "midnight_slash",
                    prompt = "midnight_slash_prompt"
                })
                if success then
                    event:setCostData(self, dat)
                    return true
                end
            end
        end,
        on_use = function(self, event, target, player, data)
            local skill = Fk.skills["midnight_slash"]
            ---@cast skill ViewAsSkill
            local card = skill:viewAs(player, event:getCostData(self).cards)
            if card then
                player.room:useCard({
                    from = player,
                    tos = event:getCostData(self).targets,
                    card = card,
                    extraUse = true,
                })
            end
        end,
    })
    midnight:addEffect("targetmod", {
        bypass_distances = function(self, player, skill, card, to)
            if card and player:hasSkill(midnight.name) then
                if type(card) == "number" then
                    return Fk:getCardById(card).color == Card.Black and player:getMark("midnight_win-turn") > 0
                else
                    return card.color == Card.Black and player:getMark("midnight_win-turn") > 0
                end
            end
        end,
    })
    midnight:addEffect(fk.CardUsing, {
        anim_type = "offensive",
        can_trigger = function(self, event, target, player, data)
            if player:hasSkill(midnight.name) and data.card.color == Card.Black and (data.card.trueName == "slash" or data.card:isCommonTrick()) and player:getMark("midnight_win-turn") > 0 and target == player then
                local room = player.room
                local pindian_target = table.find(room.alive_players, function(t, _, _)
                    return t:getMark("midnight_target-turn") > 0
                end)
                if pindian_target == nil then
                    return false
                end
                local tos = {}
                for _, t in ipairs(room.alive_players) do
                    local already_target = false
                    if data.tos then
                        for _, to in ipairs(data.tos) do
                            if to == t then
                                already_target = true
                                break
                            end
                        end
                    end
                    if t ~= player and (pindian_target:inMyAttackRange(t) or pindian_target == t) and not already_target then
                        table.insertIfNeed(tos, t)
                    end
                end
                return #tos > 0
            end
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local pindian_target = table.find(room.alive_players, function(t, _, _)
                return t:getMark("midnight_target-turn") > 0
            end)
            if pindian_target then
                event:setCostData(self, {})
                local targets = data:getAllTargets()
                for _, t in ipairs(room.alive_players) do
                    if t ~= player and (pindian_target:inMyAttackRange(t) or pindian_target == t) and not table.contains(targets, t) then
                        table.insert(event:getCostData(self), t.id)
                    end
                end
                room:setPlayerMark(player, "midnight", event:getCostData(self))
                local success, _ = room:askToUseActiveSkill(player, {
                    skill_name = "midnight_target_tip",
                    prompt = "midnight_target_tip_prompt:::" .. data.card:toLogString()
                })
                if success then
                    room:doIndicate(player, event:getCostData(self))
                end
                return success
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            for _, id in ipairs(event:getCostData(self)) do
                data:addTarget(room:getPlayerById(id))
            end
        end
    })
    midnight:addEffect("prohibit", {
        is_prohibited = function (self, from, to, card)
            if from and from:getMark("midnight_lose-turn") == 0 then
                return false
            end
            local target = table.find(Fk:currentRoom().alive_players,
                function(t, _, _) return t:getMark("midnight_target-turn") > 0 end)
            if target then
                return from:hasSkill(midnight.name) and card.color == Card.Black and to ~= player and card.type ~= Card.TypeEquip and (target:inMyAttackRange(to) or to == target)
            end
        end
    })
    local midnight_slash = fk.CreateSkill {
        name = "midnight_slash",
    }
    midnight_slash:addEffect("viewas", {
        mute_card = false,
        pattern = "slash",
        card_num = 1,
        card_filter = function(self, player, to_select, selected)
            if #selected == 0 then
                local origin = Fk:getCardById(to_select)
                local card = Fk:cloneCard("slash")
                table.insertIfNeed(card.skillNames, midnight.name)
                card:addSubcard(origin)
                return Self:canUse(card)
            end
        end,
        prompt = function(self, selected, selected_cards)
            return "midnight_slash_prompt"
        end,
        view_as = function(self, player, cards)
            if #cards ~= 1 then
                return
            end
            local origin = Fk:getCardById(cards[1])
            local card = Fk:cloneCard("slash")
            table.insertIfNeed(card.skillNames, midnight.name)
            card:addSubcard(origin)
            return card
        end,
    })
    midnight_slash:addEffect("targetmod", {
        bypass_times = function(self, player, skill, scope, card, to)
            if card and player:hasSkill(midnight.name) then
                if type(card) == "number" then
                    return Fk:getCardById(card).skillName == "midnight_slash"
                else
                    return table.contains(card.skillNames, "midnight_slash")
                end
            end
        end,
    })
    local midnight_target_tip = fk.CreateSkill {
        name = "midnight_target_tip",
    }
    midnight_target_tip:addEffect("active", {
        card_filter = Util.FalseFunc,
        target_filter = Util.FalseFunc,
        can_use = Util.TrueFunc,
        target_tip = function(self, player, to_select, selected, selected_cards, card, selectable, extra_data)
            if table.contains(player:getTableMark("midnight"), to_select.id) then
                return "midnight_extra_target"
            end
        end,
    })
    extension:loadSkillSkels { midnight, midnight_slash, midnight_target_tip }
    hy_rumia:addSkill("midnight")
    Fk:loadTranslationTable {
        ["hy_rumia"] = "露米娅",
        ["#hy_rumia"] = "暗夜捕食者",
        ["illustrator:hy_rumia"] = "しゃんぐりら",
        ["designer:hy_rumia"] = "黑曜人形",
        ["cv:hy_rumia"] = "",

        ["midnight"] = "子夜",
        [":midnight"] = "出牌阶段限一次，你可以拼点：<br>若你赢，本回合你使用黑色牌无距离限制且使用黑色【杀】或普通锦囊牌时可以指定该角色与其攻击范围内所有其他角色为额外目标；<br>若你没赢，本回合你使用黑色牌不能指定该角色与其攻击范围内其他角色为目标。<br>此拼点结算结束后，你可以将一张牌当作【杀】使用。<br>你的拼点结果确定后，若拼点牌均为黑色，你摸两张牌。",
        ["midnight_decide_select_extra"] = "子夜：是否选择该角色与其攻击范围内所有其他角色为额外目标？",

        ["midnight_slash"] = "子夜",
        ["@midnight_mark-turn"] = "子夜",
        ["midnight_win"] = "赢",
        ["midnight_lose"] = "没赢",
        ["midnight_prompt"] = "子夜：选择一名角色进行拼点",
        ["midnight_slash_prompt"] = "子夜：将一张牌当【杀】使用",

        ["midnight_target_tip"] = "子夜",
        ["midnight_target_tip_prompt"] = "子夜：你可以令%arg增加额外目标",
        ["midnight_extra_target"] = "额外目标",
    }
end
